package com.shop2cn.iapi.agentproducts.testcase;

import java.util.Objects;
import java.util.function.BiConsumer;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.AddConditionRebateBean;
import com.shop2cn.iapi.agentproducts.parameter.ListConditionTypeBean;
import com.shop2cn.iapi.agentproducts.service.ListConditionTypeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;
/**
*返佣条件类型权重列表Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ListConditionType{
	private static ListConditionTypeBean listconditiontypeBean;
	private static ListConditionTypeCall listconditiontypeCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("返佣条件类型权重列表Test");
	}

	@Before
	public void caseUp() {
		listconditiontypeBean=new ListConditionTypeBean();
		listconditiontypeCall=new ListConditionTypeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(listconditiontypeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ListConditionType_001() {
		Logger.start(true,"新建一个条件，查询权重");
		try {
			listconditiontypeBean.setUserId(501151036);
			listconditiontypeCall.setData(listconditiontypeBean);
			listconditiontypeCall.callService();			
			Logger.verifyEquals("200", listconditiontypeCall.getString("code"), "验证code");
			listconditiontypeCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("conditionTypeList").forEach(b->{
				JsonObject conditionType = b.getAsJsonObject();
				Logger.verifyEquals(conditionType.get("weight").getAsInt(), 8-conditionType.get("conditionType").getAsInt(), "验证权重");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ListConditionType_002() {
		Logger.start(true,"新用户未设置权重");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			listconditiontypeBean.setUserId(userId);
			listconditiontypeCall.setData(listconditiontypeBean);
			listconditiontypeCall.callService();			
			Logger.verifyEquals("200", listconditiontypeCall.getString("code"), "验证code");
			listconditiontypeCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("conditionTypeList").forEach(b->{
				JsonObject conditionType = b.getAsJsonObject();
				Logger.verifyEquals(conditionType.get("weight").getAsInt(), conditionType.get("conditionType").getAsInt(), "验证权重");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
}